﻿using System;
using System.Web.Mail;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using MLY;
using MLY.Dal;
using MLY.Bll;
using System.IO;



namespace MLY.LTR
{
    public partial class CreateAlert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (clsUser.CurrentUserRoleId < 0)
            {
                Response.RedirectTo("/LTR/Login.aspx?ReturnTo=" + Request.Url.ToString());
            }
            if (Request.QueryString["AlertId"] != null)
            {
                if (!IsPostBack)
                {
                    LoadExistingAlert(Request.QueryString["AlertId"]);
                    NewalertTitle.Text = "Edit alert";
                }
            }
            // DEMO CODE
            //if ((Session["UserId"].ToString() == "39") &&
            //    ((string)Session["DemoStage"] == "Alerts"))
            //{
            //    Session["DemoSubStage"] = "3";
            //    SubmitButton.CssClass = "smallBtn Btn demohighlight";
            //}
            //else
            //{
            //    //DemoPanel4.Visible = false;
            //    //DemoPanel5.Visible = false;
            //    DemoPanel6.Visible = false;
            //    DemoPanel7.Visible = false;
            //}
            
            
            //if ((string)Session["DemoCode"] == "8.1")
            //{
            //    Session["DemoCode"] = "9";
            //}
            //else
            //{
            //    DemoPanel1.Visible = false;
            //    DemoPanel2.Visible = false;
            //    DemoPanel3.Visible = false;
            //    DemoPanel4.Visible = false;
            //    DemoPanel5.Visible = false;
            //    DemoPanel6.Visible = false;
            //    DemoPanel7.Visible = false;
            //}
            // EOF DEMO CODE
        }

        protected void Page_Unload(object sender, EventArgs e)
        {
            try
            {
                // demo code
                if ((Session["UserId"].ToString() == "39") &&
                    ((string)Session["DemoStage"] == "Alerts"))
                {
                    MLY.Bll.Demo.MoveToNextDemoSubStage();
                }
                // end of demo code
            }
            catch { }
        }

        protected bool RelationCheck(object OrgRelation)
        {
            if (ExistingAlertId.Value == "0") return false;
            bool Checked = false;
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MLYConnectionString"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("AlertIsRelationChecked", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("AlertId", ExistingAlertId.Value);
                cmd.Parameters.AddWithValue("RelationId", OrgRelation.ToString());
                cmd.Parameters.Add("Answer", SqlDbType.Bit);
                cmd.Parameters["Answer"].Direction = ParameterDirection.Output;

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    Checked = (bool)cmd.Parameters["Answer"].Value;
                }
                catch (Exception ex)
                {
                    Log.WriteError(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
            return Checked;
        }
        
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            string Answer = "uninitialized";
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MLYConnectionString"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("CreateUserAlert", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("UserId", Session["UserId"].ToString());
                cmd.Parameters.AddWithValue("ExistingAlertId", ExistingAlertId.Value);
                //cmd.Parameters.AddWithValue("ConditionOrganizationRelation", CustomersClientsDDL.SelectedValue.ToString());
                cmd.Parameters.AddWithValue("ActionEmail", EmailCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("ActionMarkRow", MarkRowCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventNewRow", NewEntryCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventChangedRow", EditedCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventSplitId", EventSplitIdCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("IsCritical", CriticalCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventCustomerWorkOrderNumber", EventCustomerWorkOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventContractorWorkOrderNumber", EventContractorWorkOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventContractorLotNumber", EventContractorLotNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventSendDate", EventSendDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventRequestedDelivaryDate", EventRequestedDelivaryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventPlannedDelivaryDate", EventPlannedDelivaryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventActualDelivaryDate", EventActualDelivaryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventCustomerPriority", EventCustomerPriorityCheckBox.Checked ? "1" : "0" );
                cmd.Parameters.AddWithValue("EventQuantity", EventQuantityCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventCustomerCatalougeCode", EventCustomerCatalougeCodeCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventProductDescription", EventProductDescriptionCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventTextFieldA", EventTextFieldACheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventTextFieldB", EventTextFieldBCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventRemarks", EventRemarksCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventOrderNumber",EventOrderNumberCheckBox.Checked  ? "1" : "0");
                cmd.Parameters.AddWithValue("EventUpdateDate", EventUpdateDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventDateCreated", EventDateCreatedCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventUpdateBy", EventUpdateByCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventTotalSum", EventTotalSumCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventContractorCatalogueCode", EventContractorCatalogueCodeCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventDateFieldA", EventDateFieldACheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventDateFieldB", EventDateFieldBCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventoriginalWoForDist", EventoriginalWoForDistCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventoriginalQuantity", EventoriginalQuantityCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventOriginalPlannedDeliveryDate", EventOriginalPlannedDeliveryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventOriginalRequestedDeliveryDate", EventOriginalRequestedDeliveryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventCustomerOrderNumber", EventCustomerOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventTextFieldC", EventTextFieldCCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventCurrentLifeCycleStage", EventCurrentLifeCycleStageCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EventPreviousLifeCycleStage", EventPreviousLifeCycleStageCheckBox.Checked ? "1" : "0");

                cmd.Parameters.AddWithValue("EmailSplitId", EmailsplitIdCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailCustomerWorkOrderNumber", EmailCustomerWorkOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailContractorWorkOrderNumber", EmailContractorWorkOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailContractorLotNumber", EmailContractorLotNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailSendDate", EmailSendDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailRequestedDelivaryDate", EmailRequestedDelivaryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailPlannedDelivaryDate", EmailPlannedDelivaryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailActualDelivaryDate", EmailActualDelivaryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailCustomerPriority", EmailCustomerPriorityCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailQuantity", EmailQuantityCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailCustomerCatalougeCode", EmailCustomerCatalougeCodeCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailProductDescription", EmailProductDescriptionCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailTextFieldA", EmailTextFieldACheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailTextFieldB", EmailTextFieldBCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailRemarks", EmailRemarksCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailOrderNumber", EmailOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailUpdateDate", EmailUpdateDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailDateCreated", EmailDateCreatedCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailUpdateBy", EmailUpdatedByCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailTotalSum", EmailtotalSumCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailContractorCatalogueCode", EmailContractorCatalougeCodeCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailDateFieldA", EmailDateFieldACheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailDateFieldB", EmailDateFieldBCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailoriginalWoForDist", EmailOriginalWoFordistCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailoriginalQuantity", EmailOriginalQuantityCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailOriginalPlannedDeliveryDate", EmailOriginalPlannedDeliveryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailOriginalRequestedDeliveryDate", EmailOriginalRequestedDeliveryDateCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailCustomerOrderNumber", EmailCustomerOrderNumberCheckBox.Checked ? "1" : "0");
                cmd.Parameters.AddWithValue("EmailTextFieldC", EmailTextFieldCCheckBox.Checked ? "1" : "0");

                cmd.Parameters.AddWithValue("AlertName", AlertNameTextBox.Text.Trim());
                cmd.Parameters.Add("AlertId", System.Data.SqlDbType.Int);
                cmd.Parameters["AlertId"].Direction = System.Data.ParameterDirection.Output;
                cmd.Parameters.Add("Answer", System.Data.SqlDbType.NVarChar, 255);
                cmd.Parameters["Answer"].Direction = System.Data.ParameterDirection.Output;

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    Answer = cmd.Parameters["Answer"].Value.ToString();
                    string AlertId = cmd.Parameters["AlertId"].Value.ToString();
                    if (AlertId == null ||  AlertId == "0")
                    {
                        MessagePanel.Visible = true;
                        MessageLabel.Text = Answer;
                    }
                    else
                    {
                        
                        
                        //foreach (ListItem item in ContractorsCheckboxList.Items)
                        //{
                        //    if (item.Selected)
                        //    {
                        //        InsertAlertOrgRelations(AlertId, item.Value);
                        //    }
                        //}
                        foreach (RepeaterItem item in ContractorsCheckboxRepeater.Items)
                        {
                            if ((item.FindControl("ContractorsCheckBox") as CheckBox).Checked)
                            {
                                InsertAlertOrgRelations(AlertId, (item.FindControl("OrgRelationIdHiddenField") as HiddenField).Value);
                            } 
                        }
                        
                        //foreach (ListItem item in CustomersCheckboxList.Items)
                        //{
                        //    if (item.Selected)
                        //    {
                        //        InsertAlertOrgRelations(AlertId, item.Value);
                        //    }
                        //}
                        foreach (RepeaterItem item in CustomersCheckBoxesRepeater.Items)
                        {
                            if ((item.FindControl("CustomerCheckBox") as CheckBox).Checked)
                            { 
                                InsertAlertOrgRelations(AlertId, (item.FindControl("OrgRelationIdHiddenField") as HiddenField).Value);
                            }
                        }                        

                        Response.Redirect("/LTR/Alerts.aspx?Message=" + Answer);
                    }
                }
                catch (Exception ex)
                {
                    MessagePanel.Visible = true;
                    MessageLabel.Text = ex.Message;

                }
                finally
                {
                    conn.Close();                    
                }
            }
        }

        private void InsertAlertOrgRelations(string  AlertId, string UserOrgRelId)
        {
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MLYConnectionString"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("AlertAddUserOrgConnectionForAlert", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add("AlertId", System.Data.SqlDbType.Int);
                cmd.Parameters["AlertId"].Value = AlertId;
                cmd.Parameters.Add("UserOrgId", System.Data.SqlDbType.Int);
                cmd.Parameters["UserOrgId"].Value = UserOrgRelId;
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch { }
                finally
                {
                    conn.Close();
                }
            }
        }

        private void LoadExistingAlert(string AlertId)
        {
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MLYConnectionString"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("AlertGetExistingAlertDefinition", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add("AlertId", SqlDbType.Int);
                cmd.Parameters["AlertId"].Value = AlertId;

                SqlDataReader reader;

                try
                {
                    conn.Open();
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                        while (reader.Read())
                        {
                            if (reader.GetInt32(1) == SessParam.UserId)
                            {
                                ExistingAlertId.Value = AlertId;

                                EmailCheckBox.Checked = reader.GetBoolean(2);
                                MarkRowCheckBox.Checked = reader.GetBoolean(3);
                                NewEntryCheckBox.Checked = reader.GetBoolean(4);

                                EventSplitIdCheckBox.Checked = reader.GetBoolean(5);
                                EventCustomerWorkOrderNumberCheckBox.Checked = reader.GetBoolean(6);
                                EventContractorWorkOrderNumberCheckBox.Checked = reader.GetBoolean(7);
                                EventContractorLotNumberCheckBox.Checked = reader.GetBoolean(8);
                                EventSendDateCheckBox.Checked = reader.GetBoolean(9);
                                EventRequestedDelivaryDateCheckBox.Checked = reader.GetBoolean(10);
                                EventPlannedDelivaryDateCheckBox.Checked = reader.GetBoolean(11);
                                EventActualDelivaryDateCheckBox.Checked = reader.GetBoolean(12);
                                EventCustomerPriorityCheckBox.Checked = reader.GetBoolean(13);
                                EventQuantityCheckBox.Checked = reader.GetBoolean(14);
                                EventCustomerCatalougeCodeCheckBox.Checked = reader.GetBoolean(15);
                                EventProductDescriptionCheckBox.Checked = reader.GetBoolean(16);
                                EventTextFieldACheckBox.Checked = reader.GetBoolean(17);
                                EventTextFieldBCheckBox.Checked = reader.GetBoolean(18);
                                EventRemarksCheckBox.Checked = reader.GetBoolean(19);
                                EventOrderNumberCheckBox.Checked = reader.GetBoolean(20);
                                EventUpdateDateCheckBox.Checked = reader.GetBoolean(21);
                                EventDateCreatedCheckBox.Checked = reader.GetBoolean(22);
                                EventUpdateByCheckBox.Checked = reader.GetBoolean(23);
                                EventTotalSumCheckBox.Checked = reader.GetBoolean(24);
                                EventContractorCatalogueCodeCheckBox.Checked = reader.GetBoolean(25);
                                EventDateFieldACheckBox.Checked = reader.GetBoolean(26);
                                EventDateFieldBCheckBox.Checked = reader.GetBoolean(27);
                                EventoriginalWoForDistCheckBox.Checked = reader.GetBoolean(28);
                                EventoriginalQuantityCheckBox.Checked = reader.GetBoolean(29);
                                EventOriginalPlannedDeliveryDateCheckBox.Checked = reader.GetBoolean(30);
                                EventOriginalRequestedDeliveryDateCheckBox.Checked = reader.GetBoolean(31);
                                EventCustomerOrderNumberCheckBox.Checked = reader.GetBoolean(32);
                                EventTextFieldCCheckBox.Checked = reader.GetBoolean(33);
                                EventCurrentLifeCycleStageCheckBox.Checked = reader.GetBoolean(34);
                                EventPreviousLifeCycleStageCheckBox.Checked = reader.GetBoolean(35);

                                EditedCheckBox.Checked = (EventSplitIdCheckBox.Checked ||
                                                          EventCustomerWorkOrderNumberCheckBox.Checked ||
                                                          EventContractorWorkOrderNumberCheckBox.Checked ||
                                                          EventContractorLotNumberCheckBox.Checked ||
                                                          EventSendDateCheckBox.Checked ||
                                                          EventRequestedDelivaryDateCheckBox.Checked ||
                                                          EventPlannedDelivaryDateCheckBox.Checked ||
                                                          EventActualDelivaryDateCheckBox.Checked ||
                                                          EventCustomerPriorityCheckBox.Checked ||
                                                          EventQuantityCheckBox.Checked ||
                                                          EventCustomerCatalougeCodeCheckBox.Checked ||
                                                          EventProductDescriptionCheckBox.Checked ||
                                                          EventTextFieldACheckBox.Checked ||
                                                          EventTextFieldBCheckBox.Checked ||
                                                          EventRemarksCheckBox.Checked ||
                                                          EventOrderNumberCheckBox.Checked ||
                                                          EventUpdateDateCheckBox.Checked ||
                                                          EventDateCreatedCheckBox.Checked ||
                                                          EventUpdateByCheckBox.Checked ||
                                                          EventTotalSumCheckBox.Checked ||
                                                          EventContractorCatalogueCodeCheckBox.Checked ||
                                                          EventDateFieldACheckBox.Checked ||
                                                          EventDateFieldBCheckBox.Checked ||
                                                          EventoriginalWoForDistCheckBox.Checked ||
                                                          EventoriginalQuantityCheckBox.Checked ||
                                                          EventOriginalPlannedDeliveryDateCheckBox.Checked ||
                                                          EventOriginalRequestedDeliveryDateCheckBox.Checked ||
                                                          EventCustomerOrderNumberCheckBox.Checked ||
                                                          EventTextFieldCCheckBox.Checked ||
                                                          EventCurrentLifeCycleStageCheckBox.Checked ||
                                                          EventPreviousLifeCycleStageCheckBox.Checked);

                                AlertNameTextBox.Text = reader.GetString(36);

                                EmailsplitIdCheckBox.Checked = reader.GetBoolean(37);
                                EmailCustomerCatalougeCodeCheckBox.Checked = reader.GetBoolean(38);
                                EmailContractorWorkOrderNumberCheckBox.Checked = reader.GetBoolean(39);
                                EmailContractorLotNumberCheckBox.Checked = reader.GetBoolean(40);
                                EmailSendDateCheckBox.Checked = reader.GetBoolean(41);
                                EmailRequestedDelivaryDateCheckBox.Checked = reader.GetBoolean(42);
                                EmailPlannedDelivaryDateCheckBox.Checked = reader.GetBoolean(43);
                                EmailActualDelivaryDateCheckBox.Checked = reader.GetBoolean(44);
                                EmailCustomerPriorityCheckBox.Checked = reader.GetBoolean(45);
                                EmailQuantityCheckBox.Checked = reader.GetBoolean(46);
                                EmailProductDescriptionCheckBox.Checked = reader.GetBoolean(47);
                                EmailCustomerCatalougeCodeCheckBox.Checked = reader.GetBoolean(48);
                                EmailTextFieldACheckBox.Checked = reader.GetBoolean(49);
                                EmailTextFieldBCheckBox.Checked = reader.GetBoolean(50);
                                EmailRemarksCheckBox.Checked = reader.GetBoolean(51);
                                EmailOrderNumberCheckBox.Checked = reader.GetBoolean(52);
                                EmailUpdateDateCheckBox.Checked = reader.GetBoolean(53);
                                EmailDateCreatedCheckBox.Checked = reader.GetBoolean(54);
                                EmailUpdatedByCheckBox.Checked = reader.GetBoolean(55);
                                EmailtotalSumCheckBox.Checked = reader.GetBoolean(56);
                                EmailContractorCatalougeCodeCheckBox.Checked = reader.GetBoolean(57);
                                EmailDateFieldACheckBox.Checked = reader.GetBoolean(58);
                                EmailDateFieldBCheckBox.Checked = reader.GetBoolean(59);
                                EmailOriginalWoFordistCheckBox.Checked = reader.GetBoolean(60);
                                EmailOriginalQuantityCheckBox.Checked = reader.GetBoolean(61);
                                EmailOriginalPlannedDeliveryDateCheckBox.Checked = reader.GetBoolean(62);
                                EmailOriginalRequestedDeliveryDateCheckBox.Checked = reader.GetBoolean(63);
                                EmailCustomerOrderNumberCheckBox.Checked = reader.GetBoolean(64);
                                EmailTextFieldCCheckBox.Checked = reader.GetBoolean(65);

                                EveryChangeCheckBox.Checked = (EventSplitIdCheckBox.Checked &&
                                                               EventCustomerWorkOrderNumberCheckBox.Checked &&
                                                               EventContractorWorkOrderNumberCheckBox.Checked &&
                                                               EventContractorLotNumberCheckBox.Checked &&
                                                               EventSendDateCheckBox.Checked &&
                                                               EventRequestedDelivaryDateCheckBox.Checked &&
                                                               EventPlannedDelivaryDateCheckBox.Checked &&
                                                               EventActualDelivaryDateCheckBox.Checked &&
                                                               EventCustomerPriorityCheckBox.Checked &&
                                                               EventQuantityCheckBox.Checked &&
                                                               EventCustomerCatalougeCodeCheckBox.Checked &&
                                                               EventProductDescriptionCheckBox.Checked &&
                                                               EventTextFieldACheckBox.Checked &&
                                                               EventTextFieldBCheckBox.Checked &&
                                                               EventRemarksCheckBox.Checked &&
                                                               EventOrderNumberCheckBox.Checked &&
                                                               EventUpdateDateCheckBox.Checked &&
                                                               EventDateCreatedCheckBox.Checked &&
                                                               EventUpdateByCheckBox.Checked &&
                                                               EventTotalSumCheckBox.Checked &&
                                                               EventContractorCatalogueCodeCheckBox.Checked &&
                                                               EventDateFieldACheckBox.Checked &&
                                                               EventDateFieldBCheckBox.Checked &&
                                                               EventoriginalWoForDistCheckBox.Checked &&
                                                               EventoriginalQuantityCheckBox.Checked &&
                                                               EventOriginalPlannedDeliveryDateCheckBox.Checked &&
                                                               EventOriginalRequestedDeliveryDateCheckBox.Checked &&
                                                               EventCustomerOrderNumberCheckBox.Checked &&
                                                               EventTextFieldCCheckBox.Checked &&
                                                               EventCurrentLifeCycleStageCheckBox.Checked &&
                                                               EventPreviousLifeCycleStageCheckBox.Checked);
                                SpecificChangeCheckBox.Checked = !EveryChangeCheckBox.Checked;

                                CriticalCheckBox.Checked = reader.GetBoolean(66);

                            }
                        }
                }
                catch (Exception ex)
                {
                    Log.WriteError(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
    }
}
